/*
Disclaimer of Warranty: THE PACKAGE IS PROVIDED
BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT
ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF
THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


(c) Copyright 2013 Edward Principe
All Rights Reserved

*/
#ifndef PARSE_H
#define PARSE_H

#include <Windows.h>
#include <tchar.h>
#include <string>
#include <syntaxex.h>

using namespace std;

/////////////////////////////////////////////////////////////////
// Parse: Parser
////////////////////////////////////////////////////////////////
class Parse
{
public: // Construction
	Parse()
	{
		Init();
	}

	Parse(const Parse& rhs)
	{
		Copy(rhs);
	}

public: // Methods
	void InitBuffer(const wchar_t *buffer)
	{
		_is_string = false;
		_buffer = buffer;
		_i = _buffer.begin();
		_is_end = _i == _buffer.end();
	}
	void InitDelim(const wchar_t *delim)
	{
		_delim = delim;
	}
	void InitComment(wchar_t com)
	{
		_com = com;
	}

public: // Methods
	SyntaxErr Next(); // Parse next word

public: // Methods
	wstring GetBuffer() { return _buffer; }
	wstring GetDelim() { return _delim; }
	wstring GetWord() { return _word; }

	wchar_t GetComment() const { return _com; }

	bool IsString() const { return _is_string; }
	bool IsEnd() const { return _is_end; }

public: // Operators
	Parse& operator = (const Parse& rhs)
	{
		Copy(rhs);
		return *this;
	}

private: // Methods
	void Init() // Initializes class
	{
		_com = L'\'';
		_is_string = _is_end = false;
	}

	void Copy(const Parse& rhs)// Coies class
	{
		if (this == &rhs)
			return;

		_buffer = rhs._buffer;
		_delim = rhs._delim;
		_word = rhs._word;

		_com = rhs._com;

		_is_string = false;

		_i = _buffer.begin();
		_is_end = _i == _buffer.end();
	}

private: // Attributes
	wstring _buffer; // The buffer
	wstring _delim; // Deliminators
	wstring _word; // A word parsed
	wstring::iterator _i; // Pointer to a character in the buffer

	wchar_t _com; // Comment deliminator

	bool _is_string; // True if string
	bool _is_end; // True if end of buffer


};
#endif